//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "TestCurve.h"
using namespace Cephei::QL::Math;
#include <gen/QL/Math/Curve.h>
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Math::CTestCurve::CTestCurve (boost::shared_ptr<QuantLib::TestCurve>& childNative, Object^ owner) : CCurve(CTestCurve::typeid)
{
#ifdef HANDLE
	_phTestCurve = NULL;
#endif
	_ppTestCurve = &childNative;
    _ppCurve = new boost::shared_ptr<QuantLib::Curve> (boost::dynamic_pointer_cast<QuantLib::Curve> (*_ppTestCurve));
}
Cephei::QL::Math::CTestCurve::CTestCurve (QuantLib::TestCurve& childNative, Object^ owner) : CCurve(CTestCurve::typeid)
{
#ifdef HANDLE
	_phTestCurve = NULL;
#endif
	_ppTestCurve = new boost::shared_ptr<QuantLib::TestCurve> (&childNative);
    _ppCurve = new boost::shared_ptr<QuantLib::Curve> (boost::dynamic_pointer_cast<QuantLib::Curve> (*_ppTestCurve));
    _TestCurveOwner = owner;
    _CurveOwner = owner;
}

Cephei::QL::Math::CTestCurve::CTestCurve (CTestCurve^ copy) : CCurve(CTestCurve::typeid)
{
#ifdef HANDLE
	_phTestCurve = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppTestCurve = new boost::shared_ptr<QuantLib::TestCurve> (copy->GetShared());
        _ppCurve = new boost::shared_ptr<QuantLib::Curve> (boost::dynamic_pointer_cast<QuantLib::Curve> (*_ppTestCurve));
    }
}
Cephei::QL::Math::CTestCurve::CTestCurve (System::Type^ t) : CCurve(CTestCurve::typeid)
{
#ifdef HANDLE
	_phTestCurve = NULL;
#endif
	if (!t->IsSubclassOf(CTestCurve::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Math::CTestCurve::CTestCurve (QuantLib::Handle<QuantLib::TestCurve>& childNative, Object^ owner)  : CCurve(CTestCurve::typeid)
{
	_phTestCurve = &childNative;
	_ppTestCurve = &static_cast<boost::shared_ptr<QuantLib::TestCurve>>(childNative.currentLink());
    _ppCurve = new boost::shared_ptr<QuantLib::Curve> (boost::dynamic_pointer_cast<QuantLib::Curve> (*_ppTestCurve));
    _TestCurveOwner = owner;
}
Cephei::QL::Math::CTestCurve::CTestCurve (QuantLib::Handle<QuantLib::TestCurve> childNative)  : CCurve(CTestCurve::typeid)
{
	_phTestCurve = &childNative;
	_ppTestCurve = &static_cast<boost::shared_ptr<QuantLib::TestCurve>>(childNative.currentLink());
    _ppCurve = new boost::shared_ptr<QuantLib::Curve> (boost::dynamic_pointer_cast<QuantLib::Curve> (*_ppTestCurve));
}
#endif
#ifdef STRUCT
Cephei::QL::Math::CTestCurve::CTestCurve (QuantLib::TestCurve childNative)  : CCurve(CTestCurve::typeid)
{
#ifdef HANDLE
	_phTestCurve = NULL;
#endif
	_ppTestCurve = new boost::shared_ptr<QuantLib::TestCurve> (new QuantLib::TestCurve (childNative));
    _ppCurve = new boost::shared_ptr<QuantLib::Curve> (boost::dynamic_pointer_cast<QuantLib::Curve> (*_ppTestCurve));
}
#endif

Cephei::QL::Math::CTestCurve::~CTestCurve ()
{
    if (_ppTestCurve != NULL)
    {
	    delete _ppTestCurve;
        _ppTestCurve = NULL;
    }
}
Cephei::QL::Math::CTestCurve::!CTestCurve ()
{
    if (_ppTestCurve != NULL)
    {
	    delete _ppTestCurve;
    }
}
QuantLib::TestCurve& Cephei::QL::Math::CTestCurve::GetReference ()
{
    if (_ppTestCurve == NULL) throw gcnew NativeNullException ();
	return **_ppTestCurve;
}
boost::shared_ptr<QuantLib::TestCurve>& Cephei::QL::Math::CTestCurve::GetShared ()
{
    if (_ppTestCurve == NULL) throw gcnew NativeNullException ();
	return *_ppTestCurve;
}
QuantLib::TestCurve* Cephei::QL::Math::CTestCurve::GetPointer ()
{
    if (_ppTestCurve == NULL) throw gcnew NativeNullException ();
	return &**_ppTestCurve;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::TestCurve>& Cephei::QL::Math::CTestCurve::GetHandle ()
{
	if (_phTestCurve == NULL)
	{
		_phTestCurve = new Handle<QuantLib::TestCurve> (*_ppTestCurve);
	}
	return *_phTestCurve;
}
#endif
bool Cephei::QL::Math::CTestCurve::HasNative () 
{
	return (_ppTestCurve != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

